<ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
	    xmlns:ui="http://java.sun.com/jsf/facelets"
	    xmlns:c="http://java.sun.com/jsp/jstl/core"
	    template="/templates/main.xhtml">
	<ui:define name="title">Books</ui:define>
	<ui:define name="content">
        <h:form>
            <div id="bookTable" class="padded">
                <h:dataTable rendered="#{not empty bookController.books}"
                        value="#{bookController.books}" var="book"
                        frame="box" rules="all" styleClass="boxed" cellpadding="5"
                        headerClass="id author title"
                        columnClasses="id, author, title"
                        rowClasses="odd, even">
                    <h:column>
                        <f:facet name="header">ID</f:facet>
                        <h:commandLink value="#{book.id}" action="editBook.jsf">
                            <f:setPropertyActionListener target="#{editBookBean.book}" value="${book}" />
                        </h:commandLink>
                    </h:column>
                    <h:column>
                        <f:facet name="header">Author</f:facet>
                        <h:outputText value="#{book.author}" />
                    </h:column>
                    <h:column>
                        <f:facet name="header">Title</f:facet>
                        <h:outputText value="#{book.title}" />
                    </h:column>
                </h:dataTable>
                <h:outputText style="width: 100%; background: #c0c0ff;" value="No books stored." rendered="#{empty bookController.books}" />
            </div>
            <h2>Add new book</h2>
            <fieldset id="addBookPanel" class="padded">
                <h:messages layout="table" infoClass="infoMessage" errorClass="errorMessage" />
                <h:panelGrid columns="2">
                    <h:outputLabel value="Author:" for="author" />
                    <h:inputText id="author" value="#{bookController.author}"
                            required="true" requiredMessage="Author is required." maxlength="30" style="width: 300px;" />
                    <h:outputLabel value="Title:" for="title" />
                    <h:inputText id="title" value="#{bookController.title}"
                            required="true" requiredMessage="Title is required." maxlength="50" style="width: 300px;" />                 
                </h:panelGrid>
                <h:commandButton value="Add" action="#{bookController.doAddBook}" />
            </fieldset>
        </h:form>
	</ui:define>
</ui:composition>
